(function(angular) {
	'use strict';
	angular.module("fs.waf").factory("dataPatchService", dataPatchService);
	dataPatchService.$inject = [ '$q', 'loggerFactory' ,'ajaxServiceFactory'];
	
	function dataPatchService($q, loggerFactory, ajaxServiceFactory) {
		var log = loggerFactory.getLogger("dataPatchService");
		var ajaxService = ajaxServiceFactory.buildAjaxService({
			getServiceOptions : {
				url : 'do/cda/dataList/serviceCode',
				method : 'get'
			},
			getYesNoOptions : {
				url : 'do/cda/dataList/yesno',
				method : 'get'
			}
		});
		function getDPTplParmValue() {
			var options = {
				"data" : [ {
					"value" : "java.sql.Date",
					"label" : "Date"
				}, {
					"value" : "java.lang.Double",
					"label" : "Double"
				}, {
					"value" : "java.lang.Float",
					"label" : "Float"
				} , {
					"value" : "java.lang.Integer",
					"label" : "Integer"
				} , {
					"value" : "java.lang.Long",
					"label" : "Long"
				} , {
					"value" : "java.lang.Short",
					"label" : "Short"
				} , {
					"value" : "java.lang.String",
					"label" : "String"
				} , {
					"value" : "java.sql.Timestamp",
					"label" : "Timestamp"
				} ]
			};
			return options;
		}
		
		function getServiceOptions() {
			var defer = $q.defer();
			ajaxService.getService().then(function(response) {
				defer.resolve(response);
			});
			return defer.promise;
		}
		function getYesNoOptions() {
			var defer = $q.defer();
			ajaxService.getYesNoOptions().then(function(response) {
				defer.resolve(response ? response : {});
			});
			return defer.promise;
		};
		
		function initOptions(ctrl){
			var defer1 = $q.defer();
			var defer2 = $q.defer();
			ajaxService.getYesNoOptions().then(function(response) {
				ctrl.userGlobalValueOptions = response;
				defer1.resolve();
			}, angular.noop);
			ajaxService.getServiceOptions().then(function(response) {
				ctrl.serviceCodeOptions = response;
				defer2.resolve();
			});
			return $q.all({
				defer1 : defer1.promise,
				defer2 : defer2.promise
			});
		};
		
		function initOptionForSearch(ctrl){
			var defer1 = $q.defer();
			ajaxService.getServiceOptions().then(function(response) {
				if (response && response.data)
					defer1.resolve(response);
			}, angular.noop);
			return $q.all({
				serviceOptions : defer1.promise
			});
		};
		
		return {
			initOptions : initOptions,
			initOptionForSearch : initOptionForSearch
		};
	}
})(angular);